package com.csnf.demo1.controller;


import com.csnf.demo1.pojo.Result;
import com.csnf.demo1.pojo.user;
import com.csnf.demo1.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csnf.demo1.pojo.Book;
import java.util.List;

/**
 * @author csnf
 */
@RestController
public class BookController {

    @Autowired
    BookService bookService;

    @RequestMapping("/findAll")
    public Result findAllBook(){
        List<Book> list = bookService.findAllBook();
//        return "{'code':1,message:'查询成功','data':}";
        if (list!=null && list.size()>0){
            return Result.success(list);
        }else {
            return Result.error("查询失败");
        }
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        Integer i = bookService.deleteById(id);
        if (i>0){
            return Result.success();
        }else {
            return Result.error("删除失败");
        }
    }


    //4.8号晚自习作业
    @RequestMapping("/findAllUser")
    public Result findAllUser(){
        List<user> list = bookService.findAllUser();
//        return "{'code':1,message:'查询成功','data':}";
        if (list!=null && list.size()>0){
            return Result.success(list);
        }else {
            return Result.error("查询失败");
        }
    }
}
